﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Task07_GraphGenerator
{
	class Program
	{
		static void Main(string[] args)
		{
			const int GraphNodes = 10000;
			int[,] graph = new int[GraphNodes, GraphNodes];
			Random rnd = new Random();

			for (int i = 0; i < GraphNodes; i++)
			{
				int vertexesCount = rnd.Next(1, GraphNodes / 20);
				for (int j = 0; j < vertexesCount; j++)
				{
					int newVertex = rnd.Next(1, GraphNodes);
					while (graph[i, newVertex] != 0)
					{
						newVertex = rnd.Next(1, GraphNodes);
					}

					graph[i, newVertex] = 1;
				}
			}

            Console.Write(ConvertToAdjacencyList(graph));

            //StringBuilder graphMatrix = new StringBuilder();
            //graphMatrix.AppendLine(GraphNodes.ToString());

            //for (int i = 0; i < GraphNodes; i++)
            //{
            //    for (int j = 0; j < GraphNodes; j++)
            //    {
            //        graphMatrix.AppendFormat("{0}, ", graph[i, j]);
            //    }
            //    graphMatrix.Remove(graphMatrix.Length - 2, 1);
            //    graphMatrix.AppendLine();
            //}

			//Console.WriteLine(graphMatrix.ToString());
		}

        static string ConvertToAdjacencyList(int[,] graph)
        {
            StringBuilder adjacensyList = new StringBuilder();

            adjacensyList.AppendLine(graph.GetLength(0).ToString());
            for (int i = 0; i < graph.GetLength(0); i++)
            {
                for (int j = 0; j < graph.GetLength(1); j++)
                {
                    if (graph[i, j] == 1)
                    {
                        adjacensyList.AppendFormat("{0} ", j);
                    }
                }
                adjacensyList.Remove(adjacensyList.Length - 1, 1);
                adjacensyList.AppendLine();
            }

            return adjacensyList.ToString();
        }
	}
}
